﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Xml.Linq;
using Distrackting.BusinessLayer;
using Distrackting.DataLayer;
using System.Collections.Generic;



namespace Distrackting.PresentationLayer
{
    public partial class AreaPessoalFotos : System.Web.UI.Page
    {
        private Hashtable ht = new Hashtable();
        private int pos = 0;
        private int index = 0;
        protected void Page_Load(object sender, EventArgs e)
        {
            if (Session["user_guid"] == null)
            {
                Mensagens.AdicionarErro("Para ver esse recurso é necessário estar autenticado.");
                Response.Redirect(ResolveUrl("Public.aspx"));
            }


            List<Foto> fotos = GerirPercursos.getFotosByUtilizador(new Guid(Session["user_guid"].ToString()));
            if (fotos.Count == 0)
            {
                Image1.ImageUrl = "~/PresentationLayer/Images/no_fotos.png";
                Btn_Next.Visible = false;
                Btn_Previous.Visible = false;
                Label_data.Visible = false;
                Label_lat.Visible = false;
                Label_lon.Visible = false;
                Label_user.Visible = false;
                Label1.Visible = false;
                Label2.Visible = false;
                Label3.Visible = false;
                Label4.Visible = false;
            }
            else
            {
                foreach (Foto f in fotos)
                {
                    ht.Add(index, f.url);
                    index++;
                }
                Image1.ImageUrl = ((Foto)ht[pos]).url.ToString();
                Label_user.Text = ((Foto)ht[pos]).Utilizador.nome.ToString();
                Label_data.Text = ((Foto)ht[pos]).data_hora.ToString();
                Label_lat.Text = ((Foto)ht[pos]).Ponto.lat.ToString();
                Label_lon.Text = ((Foto)ht[pos]).Ponto.lng.ToString();
            }
            
        }

        protected void Btn_Previous_Click(object sender, EventArgs e)
        {
            Btn_Next.Enabled = true;
            if (pos > 0) { pos--; }
            if (pos == 0) { Btn_Previous.Enabled = false; }
            Image1.ImageUrl = ((Foto)ht[pos]).url.ToString();
            Label_user.Text = ((Foto)ht[pos]).Utilizador.nome.ToString();
            Label_data.Text = ((Foto)ht[pos]).data_hora.ToString();
            Label_lat.Text = ((Foto)ht[pos]).Ponto.lat.ToString();
            Label_lon.Text = ((Foto)ht[pos]).Ponto.lng.ToString();
        }

        protected void Btn_Next_Click(object sender, EventArgs e)
        {
            Btn_Previous.Enabled = true;
            if (pos < index) { pos++; }
            if (pos + 1 == index) { Btn_Next.Enabled = false; }
            Image1.ImageUrl = ((Foto)ht[pos]).url.ToString();
            Label_user.Text = ((Foto)ht[pos]).Utilizador.nome.ToString();
            Label_data.Text = ((Foto)ht[pos]).data_hora.ToString();
            Label_lat.Text = ((Foto)ht[pos]).Ponto.lat.ToString();
            Label_lon.Text = ((Foto)ht[pos]).Ponto.lng.ToString();
        }
    }
}
